package com.king.reference;

import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;

/**
 * @author taomk
 * @version 1.0
 * @since 15-1-27 下午11:02
 */
public class CheckRefQueue extends Thread {

	private ReferenceQueue<MyObject> referenceQueue;

	public CheckRefQueue(ReferenceQueue<MyObject> referenceQueue) {
		this.referenceQueue = referenceQueue;
	}

	@Override
	public void run() {
		try {
			Reference<MyObject> obj = (Reference<MyObject>) referenceQueue.remove();
			// 此处，可以进行obj对象相关资源的销毁
			if (obj != null) {
				System.out.println("Object for SoftReference is " + obj.get());
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
